﻿using Cl.Entity.DataBaseEntity.Goods;
using Cl.Model.DataBaseEntityDtos.Goods.BaseGoods;
using Cl.Model.DataBaseEntityDtos.Shops.BaseShop;
using Cl.Model.Results;
using Cl.Service.Service.Goods.BaseGoods;
using Cl.Service.Service.Shops.BaseShop;
using Cl.WebApi.Controllers;
using Cl.WebApi.SwaggerModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Cl.WebApi.Areas.Customer.Goods
{

    /// <summary>
    /// 商品管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = Grouping.ClientGroup)]
    public class BaseGoodsController : BaseController
    {

        private readonly IBaseGoodsService BaseGoodsService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public BaseGoodsController(IBaseGoodsService baseGoodsService)
        {
            BaseGoodsService = baseGoodsService;
        }


        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<PageResultModel<BaseGoodsOutputDto>> Get([FromQuery] SearchBaseGoodsDto request)
        {
            return BaseGoodsService.Query(request);
        }

        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfoModel> Post([FromBody] BaseGoodsInputDto value)
        {
            if (value == null)
                return GetResult.Error("参数不能为null");
            value.ShopId = 1;
            value.GroupId = 1;
            var result = await BaseGoodsService.Save(value);
            return result;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ResultInfoModel> Put([FromBody] BaseGoodsInputDto value)
        {
            return BaseGoodsService.Update(value);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public Task<ResultInfoModel> Delete([FromBody] List<int> ids)
        {
            return BaseGoodsService.Delete(ids);
        }


        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost("Audit")]
        public async Task<ResultInfoModel> Audit([FromBody] BaseGoodsAuditDto obj)
        {
            if (obj == null) return GetResult.Error("参数不能为null");
            var result = await BaseGoodsService.Audit(obj.GoodsIds, obj.AuditResult, obj.AuditRemark);
            return result;
        }


        /// <summary>
        /// 上传商品图
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost("UploadGoodsImageFile")]
        public async Task<ResultInfoModel> UploadGoodsImageFile([FromForm] GoodsFileInputDto obj)
        {
            return await BaseGoodsService.UploadGoodsImageFile(obj);
            //return null;
        }

    }
}
